#define _CRT SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<iostream>
using namespace std;

void swap(int* a, int* b)
{
    int temp = *a;
    *a = *b;
    *b = temp;
}

void My_arrange(int* arr, int k, int n)
{
    if (k == n)
    {
        for (int i = 0; i < n; i++)
            cout << arr[i];
        cout << endl;
    }
    else
    {
        for (int i = k; i < n; i++)
        {
            swap(&arr[i], &arr[k]);
            My_arrange(arr, k + 1, n);
            swap(&arr[i], &arr[k]);
        }
    }
}


int main()
{
    int arr[50] = { 0 };
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        arr[i] = i+1;
    }
    My_arrange(arr, 0, n);
    return 0;
}
